import time
from selenium.webdriver.common.by import By
from .base import BasePage, BaseHandle
from hmAutoTest.utils import UtilsDriver


class LoginPage(BasePage):
    def __init__(self):
        super().__init__()
        self.my_button = (By.XPATH, "//*[@text='我的']")
        self.phone_button = (By.XPATH, "//*[@text='login']")
        self.login_button = (By.CLASS_NAME, "android.widget.Button")

    def find_my_button(self):
        return self.get_element(self.my_button)

    def find_phone_button(self):
        return self.get_element(self.phone_button)

    def find_login_button(self):
        return self.get_element(self.login_button)


class LoginHandle(BaseHandle):
    def __init__(self):
        self.login_page = LoginPage()

    def click_my_button(self):
        self.login_page.find_my_button().click()

    def click_phone_button(self):
        self.login_page.find_phone_button().click()

    def click_login_button(self):
        self.login_page.find_login_button().click()


class LoginProxy:
    def __init__(self):
        self.login_handle = LoginHandle()

    def go_index(self):
        self.login_handle.click_my_button()
        self.login_handle.click_phone_button()
        time.sleep(2)
        self.login_handle.click_login_button()